package com.qf.action;

import com.qf.utils.ShiroUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginAction {
    /*登录的action*/
    @RequestMapping("/doLogin.do")
    public String login(HttpServletRequest request,String userName,String passWord){
        UsernamePasswordToken token = new UsernamePasswordToken(userName,passWord);
        Subject subject = ShiroUtils.getSubject();
        try {
            subject.login(token);
        } catch (AuthenticationException e) {
            System.out.println("登录失败");
            e.printStackTrace();
            return "login";
        }
        return "forward:/houList.do";
    }
    @RequestMapping("/loginout.do")
    public String logout(HttpServletRequest request){
        ShiroUtils.logout();
        return "redirect:/login.jsp";
    }
}
